$('.right-titleicon').on("click", function(e) {
	projectVM.showMenulist()
})

projectVM = new Vue({
	el: "#content",
	data: {
		isMyEdit: false,
		// 是否是编辑
		isEdit: false,
		// 编辑对应行
		index: 0,
		approveCodeName: '',
		// 流程id
		workId: "af5314741e95481f8d5035394b87d4d0", // 获取流程日志所需待办Id
		addOrEdit: false,
		onStatus: false,
		showPop: false,
		showMenu: false,
		isApprove: false,
		diffCurrent: {},
		diffCurrentId: '',
		saveDiffCurrentInfoList: [],
		//删除数据
		delNetSafeDeviceInfoList: [],
		formData: {
			"diffCurrentInfoId": "",
			"diffCurrentId": "",
			"surveyStaffCode": "PXMWWZI",
			"surveyStaffName": "王志",
			"tutelageStaffCode": "P627306",
			"tutelageStaffName": "杨磊",
			"testTime": "2021-11-24 11:02:57",
			"voltageClass": "220",
			"protectionDevice": "",
			"deviceModel": "",
			"factory": "",
			"deviceVersion": "",
			"iacd": '',
			"ibcd": '',
			"iccd": '',
			"iazd": '',
			"ibzd": '',
			"iczd": '',
			"remark": "",
			"client": "NEIOS",
			"dataSource": "NEIOS_APP"+localStorage.getItem("currVersion"),
			"status": "",
			"dataStatus": "1",
			"createBy": "PXMWWZI",
			"createStaffName": "王志",
			"createDate": "2021-11-24 11:03:07",
			"modifyBy": "PXMWWZI",
			"modifyStaffName": "王志",
			"modifyDate": "2021-11-24 11:03:05",
			"reserveField1": "",
			"reserveField2": "",
			"reserveField3": "",
			"reserveField4": "",
			"reserveField5": ""
		},
		defectInfoList: [],
		onlyselect: false,
		menuList: [{
			name: '新增',
			path: 'list.html'
		}, {
			name: '列表',
			path: 'index.html'
		}, ],
		filterText: 'all', //筛选条件
		list: [],
		workNode: [],
		tutelageStaffCodeName: '',
		tutelageStaffCode: '',
		tutelageStaffName: '',
		currentUser: {},
		approveDes: '',
		approveDialogTips: true,
		staus: '',
		voltageeClass:[],
	},
	components: {
		personselect,
		processlog,
		selectitem
	},
	created() {
		// 获取local数据
		console.log(localStorage.getItem('neiosGoDetail'))
		this.workId = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.workId
		console.log(this.workId)
		console.log(localStorage.getItem('neiosUser'))
		this.currentUser = JSON.parse(localStorage.getItem('neiosUser'))
		//网络安全列表
		let param = {
			"workId": this.workId,
			currentUser:this.currentUser 
		}
		let dictCodes =
			'DIFF_VOLTAGECLASS';
		let dict = mui.neiosCommon.queryDict(dictCodes, (data) => {
			if (data != '') {
				// this.TRAINING_SOURCE = data.SAFETY_SITUATION
				// this.NET_SAFE_INFO = data.NET_SAFE_INFO
				// console.log(mui.neiosCommon.dictTransform(data.SAFETY_SITUATION))
				this.voltageeClass = data.DIFF_VOLTAGECLASS;
				console.log(this.voltageeClass)
				
			}
		})
		//获取列表
		mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/getDiffCurrentByWorkId', param,
			(data) => {
				if (data.code == '0') {
					this.status = data.data ? data.data.status : '';
					// this.status = 32
					if (this.status == '32') {
						this.isMyEdit = false
					} else {
						this.isMyEdit = true
					}
					this.list = data.data ? data.data.diffCurrentInfoList : []
					this.diffCurrentId = data.data ? data.data.diffCurrentId : ''
				} else {
					mui.toast("获取数据失败：" + data.msg);
				}
			},
			(data) => {
				mui.toast("获取数据失败：" + data.msg);
			}
		);
		//获取节点
		mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/getWorkNodeByStatus', param,
			(data) => {
				if (data.code == '0') {
					this.workNode = data.data;
					if (this.workNode.length == '2') {
						this.workNode = this.workNode.filter(node => {
							return this.currentUser["userId"] != node.nodeDealStaffCode;
						});
						this.tutelageStaffCodeName = `[${this.workNode[0].nodeDealStaffCode}]${this.workNode[0].nodeDealStaffName}`;
						this.tutelageStaffCode = this.workNode[0].nodeDealStaffCode;
						this.tutelageStaffName = this.workNode[0].nodeDealStaffName;
					} else if (this.workNode.length == '1') {
						console.log(this.status)
						if (this.status == '32') {
							this.tutelageStaffCodeName = this.currentUser.userName
							this.tutelageStaffCode = this.currentUser.userId
							this.tutelageStaffName = this.currentUser.name
						} else {
							mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/getBackNodeByWorkId', param,
								(data) => {
									if (data.code == '0') {
										this.workNode = data.data;
										console.log(JSON.stringify(data))
										this.tutelageStaffCodeName =
											`[${this.workNode.nodeDealStaffCode}]${this.workNode.nodeDealStaffName}`;
										this.tutelageStaffCode = this.workNode.nodeDealStaffCode;
										this.tutelageStaffName = this.workNode.nodeDealStaffName;
									} else {
										mui.toast("获取数据失败：" + data.msg);
									}
								},
								(data) => {
									mui.toast("获取数据失败：" + data.msg);
								}
							);
						}

					}
				} else {
					mui.toast("获取数据失败：" + data.msg);
				}
			},
			(data) => {
				mui.toast("获取数据失败：" + data.msg);
			}
		);
	},
	methods: {
		goBack() {
			let page2 = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");  
			let param = {}
			param.isRefresh = true
			mui.fire(page2, 'isRefresh', param); 
			mui.back()
		},
		mychange() {
			console.log(JSON.stringify(this.$refs.myPerson.chooseItem))
			console.log(this.$refs.myPerson.formInline.member)
			this.formData.protectionDevice = this.$refs.myPerson.chooseItem.protectionDevice
			if (this.$refs.myPerson.chooseItem.deviceModel != '' && this.$refs.myPerson.chooseItem.deviceModel != null) {
				this.formData.deviceModel = this.$refs.myPerson.chooseItem.deviceModel;
			}
			if (this.$refs.myPerson.chooseItem.factory != '' && this.$refs.myPerson.chooseItem.factory != null) {
				this.formData.factory = this.$refs.myPerson.chooseItem.factory;
			}
			if (this.$refs.myPerson.chooseItem.deviceVersion != '' && this.$refs.myPerson.chooseItem.deviceVersion != null) {
				this.formData.deviceVersion = this.$refs.myPerson.chooseItem.deviceVersion;
			}
		},
		// 退回&&通过
		saveApprove() {
			this.buildSaveParam()
			//通过
			if (this.approveDialogTips) {
				let params = {
					"workId": this.workId,
					"approveDes": this.approveDes,
					"currentUser": this.currentUser,
					"params": {
						"workId": this.workId,
						"diffCurrent": this.diffCurrent,
						"diffCurrentInfoList": this.saveDiffCurrentInfoList,
						"currentUser": this.currentUser,
						"saveOrSubmit": "save",
						"tutelageStaffCode": this.tutelageStaffCode,
						"tutelageStaffName": this.tutelageStaffName
					}
				};
				mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/diffCurrentAdopt', params,
					(data) => {
						if (data.code == '0') {
							mui.toast("通过成功");
							this.goBack()
						}
					},
					() => {
						console.log("通过失败!");
					}
				);

			} else {
				// 退回  
				if (this.approveDes) {
					let params = {
						"workId": this.workId,
						"workType": '0112', //差动电流类型,
						"nodeDealStaffCode": this.currentUser.userId,
						"nodeDealStaffName": this.currentUser.name,
						"approveDes": this.approveDes,
						"nodeDealStaffRole": '2',
						"forwardNode": '1',
						"nodeVisibleRange": '20',
						"params": {
							"workId": this.workId,
							"diffCurrent": this.diffCurrent,
							"diffCurrentInfoList": this.saveDiffCurrentInfoList,
							"currentUser": this.currentUser,
							"saveOrSubmit": "save",
							"tutelageStaffCode": this.tutelageStaffCode,
							"tutelageStaffName": this.tutelageStaffName
						}
					};
					mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/diffCurrentBack', params,
						(data) => {
							if (data.code == '0') {
								mui.toast("退回成功");
								this.goBack()
							}
						},
						() => {
							console.log("退回失败!");
						}
					);
				} else {
					mui.toast("请输入意见描述");
				}
			}
			this.clearDefectInfo()
		},
		clickStop() {

		},
		// 清除隐患描述
		clearDefectInfo() {
			this.isApprove = false
			this.approveDes = ''
		},
		// 初始退回确认按钮
		approveInitDefectInfo(type) {
			if (type == 'approve') {
				this.approveDialogTips = true
			} else {
				this.approveDialogTips = false
			}
			this.isApprove = true
		},
		// 删除
		del(item, index) {
			var btnArray = ['取消', '确定'];
			mui.confirm('是否确认删除？', '提示', btnArray, (e) => {
				if (e.index == 1) {
					item.dataStatus = '0'
					this.list.splice(index, 1)
					if (item.diffCurrentId != null && typeof(item.diffCurrentId) != "undefined" && item.diffCurrentId !=
						"") {
						this.delNetSafeDeviceInfoList.push(item);
					}
				}
			})

		},
		// 新增添加
		addList() {
			// protectionDevice:保护装置
			// deviceModel:装置型号
			// factory:厂家
			// deviceVersion:装置版本号
			// iacd:差动电流iacd
			// ibcd:差动电流ibcd
			// iccd:差动电流iccd
			// iazd:差动电流iazd
			// ibzd:差动电流ibzd
			// iczd:差动电流iczd

			//todo 选择装置型号修改厂家 装置版本号装置型号
			if (!this.formData.protectionDevice) {
				mui.toast("请选择保护装置");
			} else 
			if (!this.formData.deviceModel) {
				mui.toast("请输入装置型号");
			} else if (!this.formData.factory) {
				mui.toast("请输入厂家");
			} else if (!this.formData.deviceVersion) {
				mui.toast("请输入装置版本号");
			} else if (!this.formData.iacd) {
				mui.toast("请输入差动电流iacd");
			} else if (!this.formData.ibcd) {
				mui.toast("请输入差动电流ibcd");
			} else if (!this.formData.iccd) {
				mui.toast("请输入差动电流iccd");
			} else if (!this.formData.iazd) {
				mui.toast("请输入差动电流iazd");
			} else if (!this.formData.ibzd) {
				mui.toast("请输入差动电流ibzd");
			} else if (!this.formData.iczd) {
				mui.toast("请输入差动电流iczd");
			} else {
				this.addOrEdit = false
				if (!this.isEdit) {
					this.list.unshift(this.formData)
					this.formData = {}
				} else {
					this.formData.modifyStaffName = this.currentUser.name
					this.formData.modifyBy = this.currentUser.userId
					this.formData.modifyDate = this.getTime(new Date())
					this.list.splice(this.index, 1, this.formData)
				}
				this.clearFormateData()
			}
		},
		// 清楚编辑信息
		clearFormateData() {
			this.addOrEdit = false
			this.formData = {
				"diffCurrentInfoId": "",
				"diffCurrentId": "",
				"surveyStaffCode": "PXMWWZI",
				"surveyStaffName": "王志",
				"tutelageStaffCode": "P627306",
				"tutelageStaffName": "杨磊",
				"testTime": "2021-11-24 11:02:57",
				"voltageClass": "220",
				"protectionDevice": "",
				"deviceModel": "",
				"factory": "",
				"deviceVersion": "",
				"iacd": '',
				"ibcd": '',
				"iccd": '',
				"iazd": '',
				"ibzd": '',
				"iczd": '',
				"remark": "",
				"client": "NEIOS",
				"dataSource": "NEIOS_APP"+localStorage.getItem("currVersion"),
				"status": "",
				"dataStatus": "1",
				"createBy": "PXMWWZI",
				"createStaffName": "王志",
				"createDate": "2021-11-24 11:03:07",
				"modifyBy": "PXMWWZI",
				"modifyStaffName": "王志",
				"modifyDate": "2021-11-24 11:03:05",
				"reserveField1": "",
				"reserveField2": "",
				"reserveField3": "",
				"reserveField4": "",
				"reserveField5": ""
			}
		},
		buildSaveParam() {
			// 页面的数组数据和删除的数组数据合并
			this.saveDiffCurrentInfoList = this.list.concat(this.delNetSafeDeviceInfoList);
			// 批次id
			let diffCurrentId = '';
			// 批次id为空代表点击的是新增
			if (this.diffCurrentId == '') {
				// 批次id
				diffCurrentId = mui.neiosCommon.getUuidv4();
				// 记录一下批次id 为了页面增删改的时候不继续增加批次
				this.diffCurrentId = diffCurrentId;
				// 差动电流批次批次
				this.diffCurrent.diffCurrentId = diffCurrentId; // 主键id
				this.diffCurrent.workId = this.workId //工作主键id
				this.diffCurrent.client = 'NEIOS'; // 客户id
				this.diffCurrent.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion"); // 数据来源
				this.diffCurrent.dataStatus = '1'; // 数据状态
				this.diffCurrent.status = '21'
				this.diffCurrent.createBy = this.currentUser.userId // 创建人
				this.diffCurrent.createDate = this.getTime(new Date()) //创建时间
				this.diffCurrent.createStaffName = this.currentUser.name; //创建人姓名
				this.diffCurrent.modifyBy = this.currentUser.userId; //修改人
				this.diffCurrent.modifyDate = this.getTime(new Date()) //修改时间
				this.diffCurrent.modifyStaffName = this.currentUser.name; //修改人姓名
			} else {
				// 点击修改，id用原有的，并把批次数据清空
				diffCurrentId = this.diffCurrentId;
				this.diffCurrent = {};
			}
			// 差动电流明细
			this.saveDiffCurrentInfoList.forEach(diffCurrentInfo => {
				diffCurrentInfo.diffCurrentId = diffCurrentId; // 关联的批次id
			});
		},
		add() {
			this.isEdit = false
			this.addOrEdit = true
			this.formData.diffCurrentInfoId = mui.neiosCommon.getUuidv4()
			this.formData.diffCurrentId = ''
			//当前用户
			this.formData.createBy = this.currentUser.userId
			this.formData.createStaffName = this.currentUser.name
			//监护人
			this.formData.tutelageStaffCode = this.tutelageStaffCode
			this.formData.tutelageStaffName = this.tutelageStaffName
			//测试人
			this.formData.surveyStaffCode = this.currentUser.userId
			this.formData.surveyStaffName = this.currentUser.name
			//修改人
			this.formData.modifyStaffName = this.currentUser.name
			this.formData.modifyBy = this.currentUser.userId
			this.formData.testTime = this.getTime(new Date())
			this.formData.modifyDate = this.getTime(new Date())
			this.formData.createDate = this.getTime(new Date())
		},
		//新巡视人若编辑了历史信息则对应巡视人为新巡视人否则保持为原巡视人
		changeCheck(e) {
			// this.formData.modifyBy = "P627306"; //修改人
			// this.formData.modifyDate = this.getTime(new Date()); //修改时间
			// this.formData.modifyStaffName = '栾源升' //修改人姓名
		},
		edit(item, index) {
			this.isEdit = true
			this.addOrEdit = true
			this.index = index
			this.formData = JSON.parse(JSON.stringify(item))
			this.$nextTick(()=>{
				this.$refs.myPerson.formInline.member = this.formData.protectionDevice
			})
		},
		//获取时间
		getTime(myDate, type) {
			var realYear = myDate.getFullYear();
			var myMonth = myDate.getMonth() + 1;
			var realMonth = myMonth;
			var myDay = myDate.getDate();
			var realDay = myDay;
			var myHour = myDate.getHours();
			var realHours = myHour;
			var myMinute = myDate.getMinutes();
			var realMinute = myMinute;
			var mySecond = myDate.getSeconds();
			var realSecond = mySecond;
			if (myMonth < 10) {
				realMonth = "0" + myMonth;
			}
			if (myDay < 10) {
				realDay = "0" + myDay;
			}
			if (myMinute < 10) {
				realMinute = "0" + myMinute;
			}
			if (myHour < 10) {
				realHours = "0" + myHour;
			}
			if (mySecond < 10) {
				realSecond = "0" + mySecond;
			}
			var realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' +
				realSecond;
			if (type == "sec") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' + realSecond;
			} else if (type == "min") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute;
			} else if (type == "hour") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours;
			} else if (type == "day") {
				realDate = realYear + '-' + realMonth + '-' + realDay;
			} else if (type == "month") {
				realDate = realYear + '-' + realMonth;
			} else if (type == "year") {
				realDate = realYear;
			}
			return realDate;
		},
		// 保存
		save(type) {
			this.buildSaveParam()
			if (type) {
				let param = {
					"workId": this.workId,
					"diffCurrent": this.diffCurrent,
					"diffCurrentInfoList": this.saveDiffCurrentInfoList,
					"currentUser": this.currentUser,
					"saveOrSubmit": "submit",
					"tutelageStaffCode": this.tutelageStaffCode,
					"tutelageStaffName": this.tutelageStaffName
				}
				mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/saveOrUpdateDiffCurrent', param,
					(data) => {
						if (data.code == '0') {
							mui.toast("提交成功");
							this.goBack()
						}else{
							mui.toast("提交失败");
						}
					},
					() => {
						mui.toast("提交失败");
					}
				);
			} else {
				let param = {
					"workId": this.workId,
					"diffCurrent": this.diffCurrent,
					"diffCurrentInfoList": this.saveDiffCurrentInfoList,
					"currentUser": this.currentUser,
					"saveOrSubmit": "save",
					"tutelageStaffCode": this.tutelageStaffCode,
					"tutelageStaffName": this.tutelageStaffName
				}
				mui.neiosRequst.httpRequst('/app/regularWork/diffCurrent/saveOrUpdateDiffCurrent', param,
					(data) => {
						if (data.code == '0') {
							mui.toast("保存成功");
						}else{
							mui.toast("保存失败");
						}
					},
					() => {
						mui.toast("保存失败");
					}
				);
			}
		},
		//点击菜单
		menuClick(e) {
			this.navTo(e.path)

		},
		//左上角菜单显示隐藏
		showMenulist() {
			this.showMenu ? this.showMenu = false : this.showMenu = true
		},
		//切换筛选条件
		changeFliter(e) {
			this.filterText = e
		},
		showPop() {
			this.show_popup = true
		},
		hidePopup() {
			this.show_popup = false
		},

	}

})



// mui.init({
// 	pullRefresh: {
// 		container: "#scroll", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
// 		down: { //下拉刷新
// 			style: 'circle',
// 			height: 50, //可选,默认50.触发下拉刷新拖动距离,
// 			auto: false, //可选,默认false.首次加载自动下拉刷新一次
// 			contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
// 			contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
// 			contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
// 			callback: async function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
// 				page = 0;

// 				////没有更多内容了，endPulldown 传入true， 不再执行下拉刷新
// 				mui('#scroll').pullRefresh().endPulldownToRefresh();
// 				mui('#scroll').pullRefresh().enablePullupToRefresh();
// 				mui('#scroll').pullRefresh().endPullupToRefresh(true);
// 			}
// 		},
// 		up: { //上拉加载
// 			height: 50, //可选.默认50.触发上拉加载拖动距离
// 			auto: false, //可选,默认false.自动上拉加载一次
// 			contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
// 			contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
// 			callback: async function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；

// 			}
// 		}
// 	}
// });
